package cn.neusoft.luofa603.yuejian.Activity;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;

import java.util.ArrayList;
import java.util.List;
import cn.neusoft.luofa603.yuejian.Fragment.ClubFragment;
import cn.neusoft.luofa603.yuejian.Fragment.MyFragment;
import cn.neusoft.luofa603.yuejian.Fragment.ShareFragment;
import cn.neusoft.luofa603.yuejian.Fragment.TrainingFragment;

import cn.neusoft.luofa603.yuejian.Fragment.YuejianFragment;
import cn.neusoft.luofa603.yuejian.R;
import cn.neusoft.luofa603.yuejian.databinding.ActivityMainBinding;

public class MainActivity extends ToolbarActivity<ActivityMainBinding>
        implements BottomNavigationView.OnNavigationItemSelectedListener{

    private List<Fragment> fragments = new ArrayList<>();
    private int curPageIndex;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setToolbarTitle(getString(R.string.app_name_long));
        setToolbarMenu(R.menu.tool);


        fragments.add(new TrainingFragment());
        fragments.add(new ClubFragment());
        fragments.add(new YuejianFragment());
        fragments.add(new ShareFragment());
        fragments.add(new MyFragment());

        binding.navigation.setOnNavigationItemSelectedListener(this);
        binding.navigation.setSelectedItemId(R.id.nav_training);
    }

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        System.out.println(toolbarBinding.toolbar.indexOfChild(item.getActionView()));
        switch (item.getItemId()) {
            case R.id.nav_training:
                curPageIndex = 0;
                break;
            case R.id.nav_club:
                curPageIndex = 1;
                break;
            case R.id.nav_lianmeng:
                curPageIndex = 2;
                break;
            case R.id.nav_share:
                curPageIndex = 3;
                break;
            case R.id.nav_my:
                curPageIndex = 4;
                break;
            default:
                return false;
        }
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.main_container,fragments.get(curPageIndex))
                .commit();
        return true;
    }
}
